package com.miplus.ccrm.core.service.strategy;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.core.controller.vo.LabelResVo;
import com.miplus.ccrm.core.controller.vo.strategy.*;
import com.miplus.ccrm.core.pojo.CfgActivity;
import com.miplus.ccrm.core.pojo.CfgActivityQuerydatacol;
import com.miplus.ccrm.core.mapper.CfgActivityQuerydatacolMapper;
import com.miplus.ccrm.core.pojo.MsgDefine;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author pc
* @description 针对表【cfg_activity_querydatacol(参与筛选的列)】的数据库操作Service实现
* @createDate 2024-03-28 17:28:17
*/
@Service
public class CfgActivityQuerydatacolServiceImpl extends MPJBaseServiceImpl<CfgActivityQuerydatacolMapper, CfgActivityQuerydatacol>
    implements CfgActivityQuerydatacolService{

    @Override
    public List<LabelResVo> triggerColList()
    {
        return selectJoinList(
                LabelResVo.class,
                new MPJLambdaWrapper<CfgActivityQuerydatacol>()
                        .selectAs(CfgActivityQuerydatacol::getSplicecol,LabelResVo::getValue)
                        .selectAs(CfgActivityQuerydatacol::getColdesc,LabelResVo::getLabel)
                        .selectAll(CfgActivityQuerydatacol.class)
        );
    }

    @Override
    public IPage<QuyColResVo> cfgQueryColList(QuyColReqVo paras)
    {
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                QuyColResVo.class,
                new MPJLambdaWrapper<CfgActivityQuerydatacol>()
                        .selectAs("fun_getnames('ACTIVITY.QUERY.INTYPE',t.inputtype)",QuyColResVo::getInputtypedsc)
                        .selectAll(CfgActivityQuerydatacol.class)
                        .like(JPubUtils.IsNotEmpty(paras.getColdesc()),CfgActivityQuerydatacol::getColdesc,paras.getColdesc())
                        .eq(JPubUtils.IsNotEmpty(paras.getStatus()),CfgActivityQuerydatacol::getStatus,paras.getStatus())
                        .like(JPubUtils.IsNotEmpty(paras.getTablename()),CfgActivityQuerydatacol::getTablename,paras.getTablename())
                        .orderByAsc(CfgActivityQuerydatacol::getId)
        );
    }

    @Override
    public CmdResVo cfgQueryColInsert(String $usrid,QuyColEditVo paras)
    {
        CfgActivityQuerydatacol def=new CfgActivityQuerydatacol();

        BeanUtils.copyProperties(paras,def);
        if(JPubUtils.IsEmpty(paras.getDatatype())){
            def.setDatatype(paras.getColtype());
        }
        def.setSplicecol(paras.getTableas()+"."+paras.getColname());
        def.setUpdt(new Date());
        def.setUpusr($usrid);
        int ret=baseMapper.insert(def);

        return new CmdResVo(ret,def.getId().toString());
    }

    @Override
    public CmdResVo cfgQueryColUpdate(String $usrid, QuyColEditVo paras)
    {
        CfgActivityQuerydatacol def=new CfgActivityQuerydatacol();
        BeanUtils.copyProperties(paras,def);
        if(JPubUtils.IsEmpty(paras.getDatatype())){
            def.setDatatype(paras.getColtype());
        }
        def.setSplicecol(paras.getTableas()+"."+paras.getColname());
        def.setUpdt(new Date());
        def.setUpusr($usrid);
        int ret=baseMapper.updateById(def);

        return new CmdResVo(ret,def.getId().toString());
    }

    @Override
    public CmdResVo cfgQueryColUpStatus(String $usrid, QuyColStatusVo paras)
    {
        CfgActivityQuerydatacol def=new CfgActivityQuerydatacol();
        def.setId(paras.getId());
        def.setStatus(paras.getStatus());
        def.setUpdt(new Date());
        def.setUpusr($usrid);

        int ret=baseMapper.updateById(def);

        return new CmdResVo(ret,def.getId().toString());
    }

    @Override
    public CmdResVo cfgQueryColDelete(Integer quyid)
    {
        int ret=baseMapper.deleteById(quyid);
        return new CmdResVo(ret,quyid.toString());
    }
}




